package com.ita.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.ita.dao.AreasDao;
import com.ita.pojo.Areas;
import com.ita.util.DBUtil;

public class AreasDaoImpl implements AreasDao {

	@Override
	public List<Areas> findByKey(String key,String row) {
		String sql = "select area from (select * from Areas where area like ?) where rownum < ?";
//		select * from (select * from Areas where area like '%山%') where rownum <6;
//		select * from (select * from Areas where area like '%山%') where rownum <6;
		List<Areas> list=new ArrayList<Areas>();
		Connection connection = null;
		PreparedStatement pst = null;
		Areas areas = null;
		ResultSet rs = null;
		try {
			connection = DBUtil.createConnection();
			pst = connection.prepareStatement(sql);
			pst.setString(1, key+"%");
			pst.setString(2, row);
			rs = pst.executeQuery();
			while (rs.next()) {
				areas = new Areas();
				areas.setArea(rs.getString("area"));
				list.add(areas);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(connection, pst, rs);
		}
		return list;
	}

}
